<template>
  <footer class="footer">
    <span class="todo-count"
      >剩余<strong>数量值{{ leftCount }}</strong></span
    >
    <ul class="filters">
      <li>
        <a
          :class="{ selected: s === 'all' }"
          @click="changeType('all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          href="javascript:;"
          :class="{ selected: s === 'active' }"
          @click="changeType('active')"
          >未完成</a
        >
      </li>
      <li>
        <a
          href="javascript:;"
          :class="{ selected: s === 'ok' }"
          @click="changeType('ok')"
        >
          已完成</a
        >
      </li>
    </ul>
    <button v-show="showDone" class="clear-completed" @click="clearDone">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      s: "all",
    };
  },
  props: {
    arr: {
      type: Array,
      required: true,
    },
  },
  computed: {
    leftCount() {
      return this.arr.filter((item) => !item.isDone).length;
    },
    showDone() {
      return this.arr.some((item) => item.isDone);
    },
  },
  methods: {
    clearDone() {
      this.$emit("clearDone");
    },
    changeType(type) {
      this.s = type;
      this.$emit("changeType", type);
    },
  },
};
</script>
